package com.ld.hpfs.pojo;

import java.util.ArrayList;
import java.util.Map;

import com.ld.hpfs.common.jackson.JackJson;
import com.ld.hpfs.common.utils.Tools;

/**
 * Ext的分页请求对象
 * 
 * @author bole
 * @date 2012-08-18 12:00:00
 */
public class ExtPager {
    private Integer             limit;
    private Integer             start;
    private Integer             page;

    private String              sort;
    private Map<String, String> sortMap;

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public String getSort() {
        return sort;
    }

    public String getSortField(int index) {
        ArrayList ta = JackJson.fromJsonToObject(sort, ArrayList.class);
        if (ta.size() > 0 && index < ta.size()) {
            sortMap = (Map<String, String>) ta.get(index);
        }
        
        return sortMap != null ? sortMap.get("property") : null;
    }
    
    public ArrayList<Map<String,String>> getSortField() {
    	if(Tools.isEmpty(sort)){
    		return null;
    	}
    	
        return JackJson.fromJsonToObject(sort, ArrayList.class);
    }

    public String getDir(int index) {
        ArrayList ta = JackJson.fromJsonToObject(sort, ArrayList.class);
        if (ta.size() > 0 && index < ta.size()) {
            sortMap = (Map<String, String>) ta.get(index);
        }
        
        return sortMap != null ? sortMap.get("direction") : null;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }
}
